part of '../index.dart';

class UniLinksService {
  static Future<void> init({checkActualVersion = false}) async {
    try {
      // final Uri? uri = await getInitialUri();
      // _uniLinkHandler(uri);
    } on PlatformException {
      if (kDebugMode) {
        print("(PlatformException) Failed to receive initial uri.");
      }
    } on FormatException catch (error) {
      if (kDebugMode) {
        print(
            "(FormatException) Malformed Initial URI received. Error: $error");
      }
    }
    // uriLinkStream.listen(_uniLinkHandler, onError: (error) {});
  }

  static Future<void> _uniLinkHandler(Uri? uri) async {
    if (uri == null || uri.queryParameters.isEmpty) return;
    final params = uri.queryParameters;
    final chatId = params['chatId'];
    if (chatId != null && chatId.isNotEmpty) {
      ImManager.jumpChat(chatId);
      return;
    }
  }
}
